package cn.ibizlab.util.adapter.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.ibizsys.central.ISystemPersistentAdapter;
import net.ibizsys.central.cloud.core.ServiceSystemRuntime;
import net.ibizsys.central.database.ISysDBSchemeRuntime;
import net.ibizsys.central.dataentity.IDataEntityRuntime;
import net.ibizsys.central.service.ISysServiceAPIRuntime;
import net.ibizsys.central.system.ISystemModuleRuntime;
import net.ibizsys.central.system.ISystemModuleUtilRuntime;
import net.ibizsys.model.system.IPSSystemModule;

/**
 * adapter 系统运行时对象：用于将构造 adapter 实体运行时对象
 */
@Slf4j
public class DefaultAdapterSystemRuntime extends ServiceSystemRuntime {

    /**
     * 构造 adapter 实体运行时对象
     *
     * @return
     */
    @Override
    protected IDataEntityRuntime createDefaultDataEntityRuntime() {
        return new DefaultAdapterDataEntityRuntime();
    }

    /**
     * 构造 adapter 数据库运行时对象
     *
     * @return
     */
    @Override
    protected ISysDBSchemeRuntime createDefaultSysDBSchemeRuntime() {
        return new DefaultAdapterDBSchemeRuntime();
    }

    /**
     * 构造adapter 持久层适配器对象
     * @return
     */
    @Override
    protected ISystemPersistentAdapter createSystemPersistentAdapter() {
        return new DefaultAdapterSystemPersistentAdapter();
    }

    @Override
    protected ISysServiceAPIRuntime createDefaultSysServiceAPIRuntime() {
        return new DefaultAdapterSysServiceAPIRuntime();
    }

    /**
     * 构造adapter 持久层适配器对象
     * @return
     */
    @Override
    protected ISystemPersistentAdapter createDefaultSystemPersistentAdapter() {
        return new DefaultAdapterDBPersistentAdapter();
    }

    /**
     * 临时忽略模块运行时注册异常
     *
     * @param iPSSystemModule
     * @return
     */
    @Override
    protected ISystemModuleRuntime createSystemModuleUtilRuntime(IPSSystemModule iPSSystemModule) {
        ISystemModuleUtilRuntime iSystemModuleUtilRuntime = this.getRuntimeObject(ISystemModuleUtilRuntime.class, iPSSystemModule.getUtilType());
        if (iSystemModuleUtilRuntime == null) {
            log.error(String.format("无法指定类型[%1$s]系统模块功能运行时", iPSSystemModule.getUtilType()));
            return null;
        }
        return (ISystemModuleRuntime) iSystemModuleUtilRuntime;
    }
}
